package autokeyboard.handler;

import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JTable;

import autokeyboard.gui.TablePanel;

/**
 * This Class is used to call event from PanelButton Class
 * 
 * @author HoldTheHand
 */
public class PanelButtonEvent 
{
	private TablePanelEvent		tableEvent	= new TablePanelEvent();
	
	private JTable				table;
	private ArrayList<Object[]>	listObject;

	public void setTable(JTable table)
	{
		this.table = table;
	}

	public void setListObject(ArrayList<Object[]> listObject)
	{
		this.listObject = listObject;
	}

	/**
	 * This method will delete your selected row
	 * <p>
	 * If your table has no more row it will disabled your input btDelete and
	 * your input btUp
	 * 
	 * @param index
	 * @param btDelete
	 * @param btUp
	 */
	public void deleteOneRow(int index, JButton btDelete, JButton btUp, JButton btDown)
	{
		listObject = tableEvent.deleteOneLine(listObject, index, btDelete, btUp, btDown);
		tableEvent.updateTable(table, listObject, index);
	}

	/**
	 * This method will move your selected row up one level
	 * <p>
	 * And when it is in the top of your table. It will disabled your input btUp
	 * <p>
	 * If your row is in the bottom of the table. It will enabled your input
	 * btDown
	 * 
	 * @param index
	 * @param btDown
	 * @param btUp
	 */
	public void moveUpOneLine(int index, JButton btDown, JButton btUp)
	{
		listObject = tableEvent.moveUpOneLine(listObject, index, btDown, btUp);
		tableEvent.updateTable(table, listObject, index);
		TablePanel.isChanged = true;
	}

	/**
	 * This method will move your selected row down one level
	 * <p>
	 * And when it is in the bottom of your table. It will disabled your input
	 * btDown
	 * <p>
	 * If your row is in the top of the table. It will enabled your input btUp
	 * 
	 * @param index
	 * @param btDown
	 * @param btUp
	 */
	public void moveDownOneLine(int index, JButton btDown, JButton btUp)
	{
		listObject = tableEvent.moveDownOneLine(listObject, index, btDown, btUp);
		tableEvent.updateTable(table, listObject, index);
		TablePanel.isChanged = true;
	}
	
	public void setNewTable()
	{
		
	}
}
